package com.article.controller;

import com.apis.articles.SaveArticleConfigApi;
import com.article.service.ApArticleConfigService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.usian.model.atri.pojos.ApArticleConfig;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("/article/api/v1/article_config")
public class SaveArticleConfig   implements SaveArticleConfigApi {
    @Resource
    ApArticleConfigService apArticleConfigService;



    @PostMapping("update")
    @Override
    public void updateconfig(@RequestBody HashMap hashMap) {
        String  id = (String) hashMap.get("ArticleId");
        String  enable = (String) hashMap.get("Enable");

        ApArticleConfig apArticleConfig=new ApArticleConfig();
        apArticleConfig.setArticleId(Long.valueOf(id));
        apArticleConfig.setIsDown(enable.equals("1")?true:false);
        LambdaUpdateWrapper<ApArticleConfig> qw=new LambdaUpdateWrapper<>();
        qw.eq(ApArticleConfig::getArticleId,id);
        qw.set(ApArticleConfig::getIsDown,enable);
        apArticleConfigService.update(apArticleConfig,qw);
    }

    @PostMapping("save")
    public ResponseResult saveArticleConfig(@RequestBody ApArticleConfig apArticleConfig){
        apArticleConfigService.save(apArticleConfig);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
